Skip to content

Implement unbound dns caching#35

Open
Bandit-HaxUnit wants to merge 1 commit intomasterfrom
cursor/implement-unbound-dns-caching-23a6
Open

Implement unbound dns caching#35
Bandit-HaxUnit wants to merge 1 commit intomasterfrom
cursor/implement-unbound-dns-caching-23a6

Conversation

@Bandit-HaxUnit
Copy link
Copy Markdown
Owner

@Bandit-HaxUnit Bandit-HaxUnit commented Jul 17, 2025

Implement unbound dns caching

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: DNS Resolution Failure in Docker Container

The application's DNS resolution, including subdomain bruteforce, is hard-coded to use the local Unbound DNS resolver (127.0.0.1). The docker-entrypoint.sh attempts to start Unbound but proceeds even if it fails, only issuing a warning. This creates a critical dependency without fallback to external DNS servers (e.g., 8.8.8.8). Consequently, all DNS operations will fail if Unbound is unavailable, yet the container will appear to start successfully.

main.py#L581-L582

haxunit/main.py

Lines 581 to 582 in 8973412

f"{'--stats' if not self.quick else ''} "
f"-wd {self.site} -o {self.dir_path}/dnsx_result.txt -r 127.0.0.1 -stats"

main.py#L623-L624

haxunit/main.py

Lines 623 to 624 in 8973412

f"-w data/subdomains-1000.txt -wd {self.site} "
f"-o {output_file} -r 127.0.0.1"

docker-entrypoint.sh#L18-L49

# Start Unbound DNS resolver in the background
echo "Starting Unbound DNS resolver..."
if [[ -f "/app/start-unbound.sh" ]]; then
chmod +x /app/start-unbound.sh
tmux new-session -d -s unbound "/app/start-unbound.sh"
echo "Unbound DNS resolver started in background session"
# Wait a moment for Unbound to start
sleep 3
# Test if Unbound is running
if pgrep unbound > /dev/null; then
echo "Unbound is running successfully"
else
echo "Warning: Unbound may not have started properly"
fi
else
echo "Warning: Unbound startup script not found"
fi
# Start OpenVPN in the background if the configuration file is provided.
if [[ -n "$HTB_OPENVPN_FILE" && -f "$HTB_OPENVPN_FILE" ]]; then
echo "Starting OpenVPN connection in the background..."
# Ensure the command is run in a way that doesn't block the entrypoint
tmux new-session -d -s openvpn "openvpn --config ${HTB_OPENVPN_FILE}"
else
echo "VPN not started. HTB_OPENVPN_FILE is not set or file not found."
fi
# Execute the command passed to the container (e.g., ["tail", "-f", "/dev/null"])
exec "$@"

Fix in CursorFix in Web


BugBot free trial expires on July 24, 2025
Learn more in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎


2. **`start-unbound.sh`** - Unbound initialization script
- Downloads root hints
- Initializes DNSSEC trust anchor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be extreme overhead on cpu cycles

Will check and bump.

libpcap-dev && \
libpcap-dev \
unbound \
dnsutils \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necessary?

print_info " PID: $(pgrep unbound)"
else
print_warning "✗ Unbound is not running"
return 1

This comment was marked as outdated.

print_info "Testing $domain..."

# Test with local Unbound cache
local_time=$(time (nslookup $domain 127.0.0.1 > /dev/null 2>&1) 2>&1 | grep real | awk '{print $2}')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can mock with regular gnu binaries that will populate ARP and perform lookup and don't exit errcode


# Create necessary directories
print_status "Creating directories..."
sudo mkdir -p /var/lib/unbound
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{x,y,z} (nit)


# Start Unbound
print_status "Starting Unbound DNS resolver..."
sudo unbound -c /etc/unbound/unbound.conf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

systemd?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.service file can handle health check / retries

do-udp: yes
do-tcp: yes

# Access control
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd opt for adding ssrf prot for rfc 1918, 1122, 4192, 4193, 4291 and 6598+3927


# Message cache settings
msg-cache-size: 128m
msg-cache-slabs: 4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysctl.conf may need additional tweaks

hide-identity: yes
hide-version: yes
harden-glue: yes
harden-dnssec-stripped: yes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

neg-cache-size: 16m

# Performance tuning
num-threads: 2
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysctl, open more tcp on fd

@x-stp
Copy link
Copy Markdown
Contributor

x-stp commented Jul 17, 2025

[bot] jacked in and scanned PR.
Here's the rundown on unbound implementation:

  • Daemon Protocol: spinning up the Unbound daemon raw, like a piece of pre-collapse freeware. It flatlines, and your rig just keeps humming along, feeding the application bad data while the status light stays green. That's a ghost in the state machine. need a proper watchdog, a systemd process to monitor its vitals, to re-rez it if it glitches. Otherwise, you're just a sitting duck.
  • Silent Failure is a Fast Death: monitor script just whispers a 'warning' when the DNS connection is severed. In the Gibson, that's not enough. need to trip the main breaker. exit 1. A silent failure means the baddies own your data before you even know you're compromised.
  • Open Ports to the Backend: left a gaping hole in security ICE. No firewall on private networks (RFC 1918). script-kiddie netrunner can use that to crawl your entire backend architecture. have to lock down those internal routes, or they'll become someone playground.
  • I/O Bottleneck: specced the daemon for a high-flow data stream 128 megs of cache, multi-threading—but never told the kernel to open the pipes. OS is throttling. need to jack into sysctl and crank the file descriptors, expand the network buffers. Otherwise, all that performance is just a simulation.

as an AI I can make mistakes please 👍🏻 or 👎🏻 for feedback

check_unbound_status() {
print_header "Unbound Status"

if pgrep unbound > /dev/null; then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if pgrep unbound > /dev/null; then
if ! pgrep unbound > /dev/null; then

print_header "Unbound Status"

if pgrep unbound > /dev/null; then
print_info "✓ Unbound is running"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_info " Unbound is running"
print_warning "😔 Unbound is not up"


if pgrep unbound > /dev/null; then
print_info "✓ Unbound is running"
print_info " PID: $(pgrep unbound)"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_info " PID: $(pgrep unbound)"

if pgrep unbound > /dev/null; then
print_info "✓ Unbound is running"
print_info " PID: $(pgrep unbound)"
else
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else
exit 1 # 😭

print_info "✓ Unbound is running"
print_info " PID: $(pgrep unbound)"
else
print_warning "✗ Unbound is not running"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print_warning "✗ Unbound is not running"

print_info " PID: $(pgrep unbound)"
else
print_warning "✗ Unbound is not running"
return 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return 1
print_info "🥳💾 - unbound up. holds pid $(pgrep unbound)"

else
print_warning "✗ Unbound is not running"
return 1
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fi

if [ -f "/etc/resolv.conf" ]; then
cat /etc/resolv.conf | grep -v "^#" | grep -v "^$"
else
print_warning "/etc/resolv.conf not found"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

show_dns_config() {
    print_header "DNS Configuration"

    print_info "Current DNS settings (resolv.conf / systemd-resolved):"
    if command -v resolvectl >/dev/null 2>&1; then
        resolvectl dns
    elif [ -f /etc/resolv.conf ]; then
        grep -E '^[^#[:space:]]' /etc/resolv.conf
    fi

    print_info ""
    print_info "ARP cache (kernel view):"
    ip neigh show

    print_info ""
    print_info "Active DNS queries (UDP/53 sockets):"
    ss -uap | grep ':53' || print_warning "No active DNS queries"

    print_info ""
    print_info "Kernel domain settings:"
    sysctl -a 2>/dev/null | grep 'domain'
}


print_info "Current DNS settings:"
if [ -f "/etc/resolv.conf" ]; then
cat /etc/resolv.conf | grep -v "^#" | grep -v "^$"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cat /etc/resolv.conf | grep -v "^#" | grep -v "^$"
grep -v "^#" /etc/resolv.conf | grep -v "^$"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants